//封装一个函数:获取一个结果:当前早上|上午|下午|晚上
export const getTime = () => {
    let message = ''
    //通过内置构造函数Date
    const hours = new Date().getHours()
    //情况的判断
    if (hours <= 9) {
        message = '早上'
    } else if (hours <= 12) {
        message = '上午'
    } else if (hours <= 18) {
        message = '下午'
    } else {
        message = '晚上'
    }
    return message
}
// 2024-05-27T09:13:45.000Z
export const formatTime = (date) => {
    const utcDate = new Date(date);
    // 转换为北京时间（UTC+8）
    const beijingDate = new Date(utcDate.getTime() + 8 * 60 * 60 * 1000);
    return beijingDate.toLocaleDateString('zh-CN');
}
export const formatTimeALL = (utcTimeString) => {
    const date = new Date(utcTimeString);
    const utcMilliseconds = date.getTime();
    const offsetMilliseconds = 8 * 60 * 60 * 1000;
    const beijingTime = new Date(utcMilliseconds + offsetMilliseconds);
    return beijingTime.toISOString().replace('T', ' ').substring(0, 19);
}

// 格式化时间戳
export const formatTimeStamp = (timestamp) => {
    const date = new Date(timestamp)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    return (
        year + '-' + month + '-' + day + '' + hour + ':' + minute + ':' + second
    )
}
